package estyle.auto.nkornilova.pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;

public class PageManager {
    private WebDriver driver;

    public LoginPage loginPage;
    public BankAccountMessageGridPage bankAccountMessageGridPage;
    public MessagePage messagePage;
    public InsurerFilterPage insurerFilterPage;
    public BankFilterPage bankFilterPage;
    public MainPage mainPage;


    public PageManager(WebDriver driver) {
        this.driver = driver;
        mainPage =  initElements(new MainPage(this));
        loginPage = initElements(new LoginPage(this));
        bankAccountMessageGridPage = initElements(new BankAccountMessageGridPage(this));
        messagePage =  initElements(new MessagePage(this));
        insurerFilterPage =  initElements(new InsurerFilterPage(this));
        bankFilterPage = initElements(new BankFilterPage(this));
    }

    private <T extends Page> T initElements(T page) {
        //PageFactory.initElements(driver, page);
        //PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);
        PageFactory.initElements(new DisplayedElementLocatorFactory(driver, 10), page);
        return page;
    }

    public WebDriver getWebDriver() {
        return driver;
    }

}
